package cn.skycity.common.controller;

import cn.skycity.common.service.ISysNoticeService;
import cn.skycity.framework.core.model.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skycity.common.log.annotation.Log;
import com.skycity.common.log.enums.BusinessType;
import com.skycity.framework.uaa.pojo.dto.SysNoticeBo;
import com.skycity.framework.uaa.pojo.entity.SysNotice;
import com.skycity.framework.uaa.pojo.vo.SysNoticeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 * 通知公告表 前端控制器
 * </p>
 *
 * @author YingBo.Dai
 * @since 2024-12-12
 */
@RestController
@RequestMapping("/notice")
public class SysNoticeController {


    @Autowired
    private ISysNoticeService noticeService;
//    private final DictService dictService;

//    @DubboReference
//    private final RemoteMessageService remoteMessageService;

    /**
     * 获取通知公告列表
     */
//    @SaCheckPermission("system:notice:list")
    @GetMapping("/list")
    public Result<Page<SysNotice>> list(SysNoticeBo notice, Page<SysNotice> pageQuery) {
        return Result.success(noticeService.selectPageNoticeList(notice, pageQuery));
    }

    /**
     * 根据通知公告编号获取详细信息
     *
     * @param noticeId 公告ID
     */
//    @SaCheckPermission("system:notice:query")
    @GetMapping(value = "/{noticeId}")
    public Result<SysNoticeVo> getInfo(@PathVariable Long noticeId) {
        return Result.success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
//    @SaCheckPermission("system:notice:add")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Void> add(@Validated @RequestBody SysNoticeBo notice) {
        int rows = noticeService.insertNotice(notice);
        if (rows <= 0) {
            return Result.failed();
        }
//        String type = dictService.getDictLabel("sys_notice_type", notice.getNoticeType());
//        remoteMessageService.publishAll("[" + type + "] " + notice.getNoticeTitle());
        return Result.success();
    }

    /**
     * 修改通知公告
     */
//    @SaCheckPermission("system:notice:edit")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Void> edit(@Validated @RequestBody SysNoticeBo notice) {
        noticeService.updateNotice(notice);
        return Result.success();
    }

    /**
     * 删除通知公告
     *
     * @param noticeIds 公告ID串
     */
//    @SaCheckPermission("system:notice:remove")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public Result<Void> remove(@PathVariable Long[] noticeIds) {
        noticeService.removeBatchByIds(Arrays.asList(noticeIds));
        return Result.success();
    }

}
